package com.dapao.controller;

import com.dapao.pojo.Good;
import com.dapao.pojo.Match;
import com.dapao.pojo.PageBean;
import com.dapao.pojo.Result;
import com.dapao.service.GoodService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class GoodController {

    @Autowired
    private GoodService goodService;

    @GetMapping("/good")
    public Result getGoods(@RequestParam(defaultValue = "1") Integer page,String goodKeyValue,Integer sellerId){
        log.info("获取商品列表：{}",goodKeyValue);
        PageBean pagebean = goodService.page(page,goodKeyValue,sellerId);
        return Result.success(pagebean);
    }

    @GetMapping("/goodDetail/{id}")
    public Result detail(@PathVariable Integer id) {
        log.info("查询商品细节，id：{}---detail",id);
        Good good = goodService.detail(id);
        return Result.success(good);
    }

    @PostMapping("/good/addGood")
    public Result addGood(@RequestBody Good good) {
        log.info("添加商品：{}---addGood",good);
        goodService.addGood(good);
        return Result.success();
    }

    @DeleteMapping("/good/deleteGood")
    public Result deleteGood(@RequestParam Integer id) {
        log.info("删除商品：{}---delete",id);
        goodService.deleteGood(id);
        return Result.success();
    }
}
